package com.tom.controller;

import com.tom.domain.Person;
import com.tom.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/person")
public class PersonController {

    @Autowired
    PersonService personService;

    @GetMapping("/list")
    @ResponseBody
    public List<Person> list() {
        List<Person> list = personService.list();
        return list;
    }

    @PostMapping("/save")
    @ResponseBody
    public String save(Person person) {
        System.out.println("名字是" + person.getName());
        boolean save = personService.save(person);
        if (save) {
            return "保存成功";
        } else {
            return "保存失败";
        }
    }

    @PostMapping("/remove")
    @ResponseBody
    public String remove(Integer id) {
        boolean result = personService.remove(id);
        if (result) {
            return "删除成功";
        } else {
            return "删除失败";
        }
    }

    @GetMapping("/date")
    @ResponseBody
    public String date(Date date) {
        System.out.printf("日期是" + date.toString());
        return "修改成功";
    }
}
